package com.bms.cfcmms.dao;

import com.bms.cfcmms.model.system.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

/**
 * Created by carlliu on 2016/4/10.
 */
@Repository
public class UserDao extends BaseDao<User> {

    final Logger log = LoggerFactory.getLogger(UserDao.class);

    /**
     * 根据姓名查询用户.
     *
     * @param loginName 用户名
     * @return   用户对象
     */
    public User queryForObjectByName(String loginName) {

        String sql = "select * from User where loginName=:loginName";
        SqlParameterSource sqlParameterSource = new MapSqlParameterSource(
                "loginName", loginName);
        return (User) this.namedTemplate.queryForObject(
                sql, sqlParameterSource, new User());
    }
}
